package com.tms.basic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tms.basic.pojo.domain.Menu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单Mapper接口
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {
    
    /**
     * 根据用户ID查询权限标识
     *
     * @param userId 用户ID
     * @return 权限标识列表
     */
    @Select("SELECT DISTINCT m.perms FROM tms_menu m " +
            "LEFT JOIN tms_role_menu rm ON m.id = rm.menu_id " +
            "LEFT JOIN tms_role r ON rm.role_id = r.id " +
            "LEFT JOIN tms_user u ON FIND_IN_SET(r.id, u.role_ids) " +
            "WHERE u.id = #{userId} AND m.status = 1 AND r.status = 1 " +
            "AND m.perms IS NOT NULL AND m.perms != ''")
    List<String> selectPermsByUserId(@Param("userId") Long userId);
}
